package com.ruoyi.cases.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cases.domain.JlCase;
import com.ruoyi.cases.service.IJlCaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件管理Controller
 * 
 * @author 李洪明
 * @date 2023-05-23
 */
@RestController
@RequestMapping("/cases/cases")
public class JlCaseController extends BaseController
{
    @Autowired
    private IJlCaseService jlCaseService;

    /**
     * 查询案件管理列表
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:list')")
    @GetMapping("/list")
    public TableDataInfo list(JlCase jlCase)
    {
        startPage();
        List<JlCase> list = jlCaseService.selectJlCaseList(jlCase);
        return getDataTable(list);
    }

    /**
     * 导出案件管理列表
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:export')")
    @Log(title = "案件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JlCase jlCase)
    {
        List<JlCase> list = jlCaseService.selectJlCaseList(jlCase);
        ExcelUtil<JlCase> util = new ExcelUtil<JlCase>(JlCase.class);
        util.exportExcel(response, list, "案件管理数据");
    }

    /**
     * 获取案件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jlCaseService.selectJlCaseById(id));
    }

    /**
     * 新增案件管理
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:add')")
    @Log(title = "案件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JlCase jlCase)
    {
        return toAjax(jlCaseService.insertJlCase(jlCase));
    }

    /**
     * 修改案件管理
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:edit')")
    @Log(title = "案件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JlCase jlCase)
    {
        return toAjax(jlCaseService.updateJlCase(jlCase));
    }

    /**
     * 删除案件管理
     */
    @PreAuthorize("@ss.hasPermi('cases:cases:remove')")
    @Log(title = "案件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jlCaseService.deleteJlCaseByIds(ids));
    }
}
